package com.brt.socket.rest.controller.socketConfig;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


/**
 * Created by Administrator on 2016/12/15 0015.
 */

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {


    private Logger logger = Logger.getLogger(getClass());


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        logger.info("add socket handler");
        webSocketHandlerRegistry.addHandler(myHandler(), "/sockjs/webSocketServer")  //sockjs
                .addInterceptors(new WebSocketHandshakeInterceptor())
                .withSockJS()///.setSessionCookieNeeded(true)//.setSessionCookieNeeded(false)
                .setClientLibraryUrl("/plugin/sockJS/sockjs-1.0.3.js");
    }


    @Bean
    public WebSocketHandler myHandler(){
        return new IOHandler();
    }
}
